package com.cjm.one.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.annotation.IgnoreTenantForAdmin;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.base.BaseDeleteMoreVo;
import com.cjm.one.model.system.dto.SysPostDto;
import com.cjm.one.model.system.entity.SysPost;
import com.cjm.one.system.service.SysPostService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Tag(name = "岗位管理", description = "岗位管理")
@RequestMapping("/admin/system/post")
@IgnoreTenantForAdmin
public class SysPostController {
    @Resource
    private SysPostService sysPostService;

    @PostMapping("/list")
    @Operation(summary = "岗位列表")
    @IgnoreTenantForAdmin
    public Result<Page<SysPost>> list(@RequestBody SysPostDto dto) {
        log.info("岗位列表请求参数：{}", dto);
        Page<SysPost> sysPostPage = new Page<>(dto.getCurrent(), dto.getSize());

        return Result.ok(sysPostService.selectList(sysPostPage,dto));
    }
    @GetMapping("/{id}")
    @Operation(summary = "根据id查询岗位")
    @IgnoreTenantForAdmin
    public Result<SysPost> getById(@PathVariable("id") Long id) {
        return Result.ok(sysPostService.getById(id));
    }
    @DeleteMapping("/{id}")
    @Operation(summary = "根据id删除岗位")
    @IgnoreTenantForAdmin
    public Result<Boolean> deleteById(@PathVariable("id") Long id) {
        return Result.ok(sysPostService.deleteById(id));
    }
    @PostMapping
    @Operation(summary = "新增岗位")
    @IgnoreTenantForAdmin
    public Result<Boolean> save(@RequestBody SysPost sysPost) {
        return Result.ok(sysPostService.save(sysPost));
    }
    @PutMapping
    @Operation(summary = "修改岗位")
    @IgnoreTenantForAdmin
    public Result<Boolean> update(@RequestBody SysPost sysPost) {
        return Result.ok(sysPostService.updateById(sysPost));
    }
    @DeleteMapping("/batch")
    @Operation(summary = "批量删除岗位")
    @IgnoreTenantForAdmin
    public Result<BaseDeleteMoreVo> deleteBatchIds(@RequestBody List<Long> ids) {
        return Result.ok(sysPostService.deleteBatchIds(ids));
    }
}
